<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import {ref, reactive} from 'vue'
import templateExcelObject from '@/api/template/templateExcelObject'

const crudRef = ref()
const options = reactive({
  id: 'template_excel_object',
  pageLayout: 'fixed',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  isExpand: true,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: templateExcelObject.getList,
  add: {
    show: true,
    api: templateExcelObject.save,
    auth: ['template:excelObject:save']
  },
  edit: {
    show: true,
    api: templateExcelObject.update,
    auth: ['template:excelObject:update']
  },
  delete: {
    show: true,
    api: templateExcelObject.deletes,
    auth: ['template:excelObject:delete']
  }
})

const columns = reactive([
  {
    title: "主键",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入主键"
    }
  },
  {
    title: "名称",
    dataIndex: "name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入名称"
    }
  },
  {
    title: '上级', dataIndex: 'parent_id', hide: true, formType: 'tree-select',
    dict: {url: 'template/excelObject/tree', params: {onlyMenu: true}},
    addDefaultValue: 0,
    editDefaultValue: (record) => {
      return record.parent_id == 0 ? undefined : record.parent_id
    },
    onControl: (val, maFormObject) => {
      const service = maFormObject.getColumnService()
      service.get('dto').setAttr('formType', !val? 'input' : 'select')
      service.get('dto').setAttr('title', !val? '类型' : 'DTO')
    }
  },
  {
    title: "dto",
    dataIndex: "dto",
    formType: "select",
    search: true,
    dict: {url: 'template/excelObject/dto'},
    commonRules: {
      required: true,
      message: "请选择DTO"
    }
  },
  {
    title: "结果集重写方法",
    dataIndex: "remark",
    formType: "input",
  },
  {
    title: "不可用字段",
    dataIndex: "disabled_field",
    formType: "input",
    hide: true,
    commonRules: {
      // required: true,
      message: "请输入不可用字段"
    }
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default {name: 'template:excelObject'} </script>